<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>订单详情-{$webseting.web_title}</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
	<meta name="format-detection" content="telephone=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<script src="__PUBLIC__/wap/js/flexible.js"></script>
	<script type="text/javascript" src="__PUBLIC__/wap/js/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/bootstrap/vendor/jquery-validation/jquery.validate.wap.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>
	<script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
	<link href="__PUBLIC__/wap/css/icons.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/wap/css/base.css" />
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/wap/css/order.css" />
</head>
<body class="orderinfo">
<div class="orderstate"  style="background:#6ab42f  url(../images/member/1.png) no-repeat 90% center;background-size: auto 100%; ">
	<div class="state">
		<h4>等待买家付款</h4>

	</div>
</div>

<div class="upstore ">
	<div class="store">
		<img src="__PUBLIC__/wap/img/store{$data.levelId}.png" alt=""/>
		<h4>升级成为{$data.levelName}</h4>
	</div>
	<div class="clearfix"></div>
</div>


<div class="ordermessage">
	<p class="">订单编号：<span class="num">{$data.id}</span></p>
	<p class="">订单金额：<span class="num">{$data.pay_price}</span></p>
</div>
<div class="cartlist">

	<form action="" role="form" id="form2" novalidate method="post" onSubmit="return false;">
		<div class="paytype mgt2">
			<a class="wx green"><i class="hbFntWes icon green ">&#xf1d7</i>微信支付</a>
			<if condition="$balance gt 0">
				<div class="ye"><div class="use_balance"><i class="iconfont icon">&#xe643</i>使用余额支付<span class="floatRgt"><b class="num green">￥{$balance}</b> 元</span></div>
					<input id="use_balance" name="use_balance" type="hidden" value="0">
					<div class="clearfix" style="border:none; display:none;"></div>
					<div class="field input_pwd" style="display:none;">
						<div class="label"> 密码 </div>
						<div class="field-control autoclear">
							<input type="password"  class="input-required green" name="mem_password" placeholder="请输入您的密码" value="" id="mem_password">
						</div>
					</div>
				</div>
				<script>
					$('.use_balance').click(function(){
						if($('#use_balance').val() == 0){
							$('#use_balance').val(1);
							$('.input_pwd').show();
						}else{
							$('#use_balance').val(0);
							$('.input_pwd').hide();
						}
					});
				</script>
				<else/>
				<input name="use_balance" type="hidden" value="0">
			</if>
		</div>
		<input name="pay_type" type="hidden" value="pay_online">
		<input name="order_id" id="order_id" type="hidden" value="{$data.id}" placeholder="">
	</form>
</div>
<div class="submit">
	<a href="javascript:void(0);" id="go_pay" data="{$data.order_id}"   data-tpa="GOTO_CHECKOUT" class="new-abtn-type new-mg-tb30 phone_log_btn">去支付</a>
</div>
<div class="payFs m-t-15  pay_online_goo" style="display: none;">
	<!--<div class="order-width">
		<a href="javascript:get_alipay_pay();" style="margin: 20px 0;" id="zfb" class="new-abtn-type pay_online_type onPay" data="alipay">支付宝</a>
	</div>-->
	<if condition="$is_weixin eq 1">
		<div class="order-width">
			<a href="javascript:get_weixin_pay();" id="wx" class="new-abtn-type pay_online_type green " data="wxpay"><i class="hbFntWes ">&#xf1d7</i>微信支付</a>
		</div>
	</if>
</div>

<script>
	//验证密码
	jQuery(document).ready(function() {
		//FormValidator.init();
		jQuery.validator.addMethod("passwordRequired", function(value) {
			var use_balance=$('input[name="use_balance"]').prop('checked');
			var ret=true;
			if(use_balance){
				if(!value){
					ret=false;
				}
			}
			return ret;
		});

		$("#form2").validate({
			rules: {
				mem_password: {
					passwordRequired: true,
					rangelength: [6, 20]
				}
			},
			messages: {
				mem_password:{
					passwordRequired:'<span class="icon-warning icon_warning"></span>&nbsp;请输入密码',
					rangelength:'<span class="icon-warning icon_warning"></span>&nbsp;密码请保持6-20位'
				}
			},
			focusInvalid:false,
			success: function(label) {
			},
			submitHandler: function(editform) {
				var options = {
					url :  "<?php echo U('Wap/start/start_pay_go'); ?>",
					type : "post" ,
					dataType:'json',
					target : "#loader",
					error: function(){layer.msg("服务器没有返回数据，可能服务器忙，请重试",{icon:5});},
					onwait : "正在处理信息，请稍候...",
					success: function(response){
						console.log(response);
						//$("#loader").fadeIn(500).html(response.data).fadeOut(500); 
						//$('#editform').hide(2000); 
						if(response.status==1){
							//layer.msg('支付成功',{icon:6});
							if(response.need_pay==1){
								/*  window.location.href="<?php  echo U('Wap/Mallpayment/index',array('pay_sn'=>$data['order_sn']));?>";*/
								if(response.pay_url!='' && typeof(response.pay_url)!=undefined){
									// window.location.href=response.pay_url;
									//go_weixin_pay();
									get_weixin_pay(response.pay_url);
								}else{
									layer.msg('系统错误请稍候再试', {icon: 5});
								}
								//layer.msg('修改成功，请重新登录',{icon:6});
							}else{
								layer.msg('支付成功',{icon:6,time: 1500},function(){
									/* window.location.href="<?php  echo U('wap/goodsorder/order_detail',array('id'=>$data['order_id']));?>";*/
									window.location.href="<?php  echo U('wap/start/gift_address',array('order_sn'=>$data['id']));?>";
								});
							}

							/* layer.msg("修改成功，请重新登录。",{icon:6},function(){
							 window.location.href="<?php echo U('Wap/Login/loginout'); ?>";
							 });*/
						}else{
							layer.msg(response.error,{icon:5});
						}
					}
				};
				setTimeout((function(opt){
					return function(){
						layer.msg("正在处理信息，请稍候...",{time:100000});
						$('#form2').ajaxSubmit(opt);
					}
				})(options), 300);
				return false;
			}

		});
		$('#go_pay').click(function(){

			var use_balance=$('input[name="use_balance"]').prop('checked');
			var pay_type=$('input[name="pay_type"]:checked').val();
			$('#form2').submit();
		});
	});

</script>
<script type="text/javascript">
	$(function(){
		$('#use_balance').click(function(){
			set_use_balan();
		});
		set_use_balan();
		$('input[name="pay_type"]').change(function(){
			set_pay_type();
		});
		set_pay_type();
	});
	function set_use_balan(){
		var use_balance=$('#use_balance').prop('checked');
		if(use_balance){
			$(".input_password").show();
		}else{
			$(".input_password").hide();
		}
	}
	function set_pay_type(){
		var pay_type=$('input[name="pay_type"]:checked').val();
		if(pay_type=='pay_online'){
			$(".use_balance_pay").show();
			$('#use_balance').prop('checked',true);
			set_use_balan()
		}else{
			var need_pay=$('input[name="pay_type"]:checked').attr('data-pay');
			if(need_pay==1){
			}else{
				$(".use_balance_pay").hide();
				$('#use_balance').prop('checked',false);
				set_use_balan()
			}
		}
	}
</script>

<script type="text/javascript">
	function get_weixin_pay(url){
		///需要支付
		var pay_url="<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/api/payment/wpay/jsapi_go_pay.php?pay_sn='.$data['id'].'&levelId='.$data['levelId']; ?>";
		window.location.href=pay_url+"&openid=<?php echo $_SESSION['user_open_id'];?>";
		return false;
	}

	function go_pay_online(){
		layer.closeAll(); //疯狂模式，关闭所有层
		layer.open({
			type: 1,
			shade: 0.8,//透明度
			title: false, //不显示标题
			skin: 'layui-layer-demo', //样式类名
			shadeClose: true, //开启遮罩关闭
			closeBtn: 0, //不显示关闭按钮
			area: ['80%', 'auto'],
			scrollbar: false,//浏览器滚动锁定
			content: $('.pay_online_goo'), //捕获的元素
			cancel: function(index){

				layer.close(index);
				this.content.show();
				$('.pay_online_goo').hide();
				//layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构',{time: 5000});
			}
		});
	}
	function get_alipay_pay(){
		var order_sn="<?php echo $data['id']; ?>";
		$.ajax({
			url:  "<?php echo U('wap/goodsorder/go_alipay_pay'); ?>",
			type: 'get',
			data: {order_sn:order_sn},
			dataType: 'json',
			success: function (data) {
				if (data.status == 1) {
					var pay_url = "<?php echo U('wap/Alipay/index') ?>";
					window.location.href = pay_url + '?pay_sn=' + order_sn;
				} else {
					layer.msg(data.error, {icon: 5});
					//alert(data.error)
				}
			}
		});
	}

	function go_weixin_pay(){
		layer.msg('连接FG峰购收银台....',{time: 100000});
		$.ajax({
			//  url: "{:U('wap/goodsorder/get_pay_url')}",
			url:"<?php echo U('wap/goodsorder/go_wx_pay'); ?>",
			type:'get',
			data: {pay_sn:"<?php echo $data['id']; ?>",pay:'1'},
			dataType: 'json',
			success: function(data){
				if(data.status==1){
					if(data.pay_url!='' && typeof(data.pay_url)!=undefined){
						get_weixin_pay(data.pay_url);
					}else{
						layer.msg('系统错误请稍候再试', {icon: 5});
					}
				}else{
					layer.msg(data.error, {icon: 5});
				}
			}
		});
	}
</script>
</body>
</html>